package entry75;

import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

public class StringListTest {
	StringList l;

	@Before
	public void before() {
		l = new StringList();

		l.add("abc");
		l.add("def");
		l.add("ghi");
	}

	@Test
	public void testAdd() {
		assertThat(l.size(), is(3));
	}

	@Test(expected = RuntimeException.class)
	public void testgetFail() {
		l.get(4);
	}

	@Test
	public void testGet() {
		assertThat(l.get(0), is("abc"));
		assertThat(l.get(1), is("def"));
		assertThat(l.get(2), is("ghi"));
	}

	@Test
	public void testRemove() {
		l.remove(1);

		assertThat(l.get(1), is("ghi"));
		assertThat(l.size(), is(2));

		l.remove(1);

		assertThat(l.get(0), is("abc"));
	}

	@Test
	public void testIntgral() {
		int size = l.size();
		for (int i = 0; i < size; i++) {
			l.remove(0);
		}
		assertThat(l.size(), is(0));

		String[] ss = new String[] { "가나다", "라마사", "아자차" };
		for (String s : ss) {
			l.add(s);
		}
		assertThat(l.size(), is(3));

		for (int i = 0; i < ss.length; i++) {
			assertThat(l.get(i), is(ss[i]));
		}
	}
}
